package repo

import (
	"regexp"
)

type Matcher interface {
	Match(label string) bool
}

type RegexMatcher struct {
	pattern *regexp.Regexp
}

func (m *RegexMatcher) Match(label string) bool {
	return m.pattern.MatchString(label)
}

func NewRegexMatcher(pattern string) (Matcher, error) {
	reg, err := regexp.Compile(pattern)
	if err != nil {
		return nil, err
	}

	return &RegexMatcher{pattern: reg}, nil
}

type WildcardMatcher struct {
	pattern string
}

func (m *WildcardMatcher) Match(label string) bool {
	return Wildcmp(m.pattern, label)
}

func NewWildcardMatcher(pattern string) (Matcher, error) {
	return &WildcardMatcher{pattern: pattern}, nil
}
